// exports.AssetManager = void 0;
// var $macros = require("./AL_Framework_Macros");
// var $resource = require("./AL_Framewrok_Resource");
// var a = (function () {
//     function e() {
//         this._logTag = "[RemoteLoader] ";
//     }
//     e.Instance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     e.prototype.jiazai_tupian = function (e, t) {
//         if (void 0 === t) {
//             t = !1;
//         }
//         var o = this;
//         return new Promise(function (i) {
//             if (null == e || null == e || e.length <= 0) {
//                 i(null);
//             } else {
//                 {
//                     if (t) {
//                         var n = Manager.cacheManager.remote_Caches.getSpriteFrame(e);
//                         if (n && n.data) {
//                             return void i(n.data);
//                         }
//                         Manager.cacheManager.remote_Caches.remove(e);
//                     } else {
//                         Manager.cacheManager.remote_Caches.remove(e);
//                     }
//                     o._jiazai_yuancheng_ziyuan(e, cc.Texture2D, t).then(function (t) {
//                         var o = Manager.cacheManager.remote_Caches.get(e);
//                         if (t && o) {
//                             o.data = t;
//                             o.data.name = e;
//                             var n = Manager.cacheManager.remote_Caches.shezhi_sprite_frame(e, o.data);
//                             i(n);
//                         } else {
//                             i(null);
//                         }
//                     });
//                 }
//             }
//         });
//     };
//     e.prototype.jiazai_spine_donghua_ziyuan = function (e, t, o) {
//         var a = this;
//         return new Promise(function (s) {
//             if (e && t) {
//                 var r = e + "/" + t;
//                 var c = e + "/" + t + ".atlas";
//                 var l = e + "/" + t + ".png";
//                 var d = e + "/" + t + ".json";
//                 var u = Manager.releaseManager.huoqu_yuancheng_ziyuan(r);
//                 if (u) {
//                     var h = Manager.cacheManager.remote_Caches.get(r);
//                     return void (h
//                         ? ((h.isLoaded = !0),
//                           (h.data = u),
//                           (h.info.data = u),
//                           (h.info.url = r),
//                           s(h.data),
//                           h.zhixing_wancheng(h.data))
//                         : (((h = new $resource.AL_Framewrok_Resource.CacheData()).info.resourceType =
//                               $resource.AL_Framewrok_Resource.Type.Remote),
//                           (h.info.type = sp.SkeletonData),
//                           (h.info.bundle = $macros.Macro.BUNDLE_REMOTE),
//                           (h.isLoaded = !0),
//                           (h.data = u),
//                           (h.info.data = u),
//                           (h.info.url = r),
//                           Manager.cacheManager.remote_Caches.set(r, h),
//                           s(h.data),
//                           h.zhixing_wancheng(h.data)));
//                 }
//                 var p = Manager.cacheManager.remote_Caches.get(r);
//                 p
//                     ? p.isLoaded
//                         ? s(p.data)
//                         : p.finishCb.push(s)
//                     : (((p = new $resource.AL_Framewrok_Resource.CacheData()).info.resourceType = $resource.AL_Framewrok_Resource.Type.Remote),
//                       (p.info.type = sp.SkeletonData),
//                       (p.info.bundle = $macros.Macro.BUNDLE_REMOTE),
//                       Manager.cacheManager.remote_Caches.set(r, p),
//                       a._jiazai_yuancheng_ziyuan(l, cc.Texture2D, o).then(function (e) {
//                           e
//                               ? a._jiazai_yuancheng_ziyuan(d, cc.JsonAsset, o).then(function (i) {
//                                     i
//                                         ? a._jiazai_yuancheng_ziyuan(c, cc.JsonAsset, o).then(function (o) {
//                                               if (o) {
//                                                   var n = new sp.SkeletonData();
//                                                   n.skeletonJson = i.json;
//                                                   n.atlasText = o.text;
//                                                   n.textures = [e];
//                                                   var a = t + ".png";
//                                                   n.textureNames = [a];
//                                                   p.info.url = r;
//                                                   n.name = r;
//                                                   p.data = n;
//                                                   p.isLoaded = !0;
//                                                   s(p.data);
//                                                   p.zhixing_wancheng(p.data);
//                                               } else {
//                                                   s(null);
//                                                   p.zhixing_wancheng(null);
//                                                   Manager.cacheManager.remote_Caches.remove(r);
//                                               }
//                                           })
//                                         : (s(null), p.zhixing_wancheng(null), Manager.cacheManager.remote_Caches.remove(r));
//                                 })
//                               : (s(null), p.zhixing_wancheng(null), Manager.cacheManager.remote_Caches.remove(r));
//                       }));
//             } else {
//                 s(null);
//             }
//         });
//     };
//     e.prototype._jiazai_yuancheng_ziyuan = function (e, t) {
//         return new Promise(function (o) {
//             var i = Manager.cacheManager.remote_Caches.get(e);
//             if (i) {
//                 i.isLoaded ? o(i.data) : i.finishCb.push(o);
//             } else {
//                 {
//                     (i = new $resource.AL_Framewrok_Resource.CacheData()).info.resourceType = $resource.AL_Framewrok_Resource.Type.Remote;
//                     i.info.type = t;
//                     Manager.cacheManager.remote_Caches.set(e, i);
//                     var a = Manager.releaseManager.huoqu_yuancheng_ziyuan(e);
//                     if (a) {
//                         i.isLoaded = !0;
//                         i.data = a;
//                         i.data.addRef();
//                         i.zhixing_wancheng(a);
//                         return void o(i.data);
//                     }
//                     cc.assetManager.loadRemote(e, function (e, t) {
//                         if (i) {
//                             i.isLoaded = !0;
//                             if (t) {
//                                 i.data = t;
//                                 i.data.addRef();
//                             }
//                             i.zhixing_wancheng(t);
//                             o(i.data);
//                         }
//                     });
//                 }
//             }
//         });
//     };
//     e.prototype.update = function () {};
//     e._instance = null;
//     return e;
// })();
// var s = (function () {
//     function e() {
//         this.logTag = "[AssetManager]: ";
//         this._remote = new a();
//     }
//     e.Instance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     Object.defineProperty(e.prototype, "remote", {
//         get: function () {
//             return this._remote;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     e.prototype.getBundle = function (e) {
//         return Manager.bundleManager.getBundle(e);
//     };
//     e.prototype.load = function (e) {
//         var t = e.bundle;
//         var o = e.path;
//         var i = e.type;
//         var a = e.onProgress;
//         var s = e.onComplete;
//         var r = e.shifou_yanchi_shifang_ziyuan;
//         var c = Manager.cacheManager.get(t, o);
//         if (c) {
//             c.isLoaded ? s(c) : c.finishCb.push(s);
//             c.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
//         } else {
//             {
//                 (c = new $resource.AL_Framewrok_Resource.CacheData()).info.url = o;
//                 c.info.type = i;
//                 c.info.bundle = t;
//                 c.info.shifou_yanchi_shifang_ziyuan = r;
//                 Manager.cacheManager.set(t, o, c);
//                 console.time("加载资源 : " + c.info.url);
//                 var l = Manager.releaseManager.get(t, o);
//                 if (l) {
//                     return void this._chuli_ziyuan_jiazai_wancheng(c, s, null, l);
//                 }
//                 var d = this.getBundle(t);
//                 if (!d) {
//                     var u = new Error(this.logTag + " " + t + " 没有加载，请先加载");
//                     return void this._chuli_ziyuan_jiazai_wancheng(c, s, u, null);
//                 }
//                 (l = d.get(o, i))
//                     ? this._chuli_ziyuan_jiazai_wancheng(c, s, null, l)
//                     : a
//                     ? d.load(o, i, a, this._chuli_ziyuan_jiazai_wancheng.bind(this, c, s))
//                     : d.load(o, i, this._chuli_ziyuan_jiazai_wancheng.bind(this, c, s));
//             }
//         }
//     };
//     e.prototype._chuli_ziyuan_jiazai_wancheng = function (e, t, o, i) {
//         e.isLoaded = !0;
//         var a = e;
//         o
//             ? (Log.e(this.logTag + "加载资源失败:" + e.info.url + " 原因:" + (o.message ? o.message : "未知")),
//               (e.data = null),
//               (a.data = null),
//               Manager.cacheManager.remove(e.info.bundle, e.info.url),
//               t(e))
//             : ((e.data = i), (a.data = i), t(e));
//         e.zhixing_wancheng(a);
//         e.zhixing_huoqu(a.data);
//         if (e.status == $resource.AL_Framewrok_Resource.CacheStatus.WAITTING_FOR_RELEASE && e.data) {
//             e.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
//             var s = new $resource.AL_Framewrok_Resource.Info();
//             s.url = e.info.url;
//             s.type = e.info.type;
//             s.data = e.data;
//             s.bundle = e.info.bundle;
//             s.shifou_yanchi_shifang_ziyuan = e.info.shifou_yanchi_shifang_ziyuan;
//             this.releaseAsset(s);
//         }
//         console.timeEnd("加载资源 : " + e.info.url);
//     };
//     e.prototype.loadDir = function (e) {
//         var t = e.bundle;
//         var o = e.path;
//         var i = e.type;
//         var a = e.onProgress;
//         var s = e.onComplete;
//         var r = e.shifou_yanchi_shifang_ziyuan;
//         var c = Manager.cacheManager.get(t, o);
//         if (c) {
//             c.isLoaded ? s(c) : c.finishCb.push(s);
//             c.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
//         } else {
//             {
//                 (c = new $resource.AL_Framewrok_Resource.CacheData()).info.url = o;
//                 c.info.type = i;
//                 c.info.bundle = t;
//                 c.info.shifou_yanchi_shifang_ziyuan = r;
//                 Manager.cacheManager.set(t, o, c);
//                 console.time("加载资源 : " + c.info.url);
//                 var l = Manager.releaseManager.get(t, o);
//                 if (l) {
//                     return void this._chuli_ziyuan_jiazai_wancheng(c, s, null, l);
//                 }
//                 var d = this.getBundle(t);
//                 if (!d) {
//                     var u = new Error(this.logTag + " " + t + " 没有加载，请先加载");
//                     return void this._chuli_ziyuan_jiazai_wancheng(c, s, u, null);
//                 }
//                 a
//                     ? d.loadDir(o, i, a, this._chuli_ziyuan_jiazai_wancheng.bind(this, c, s))
//                     : d.loadDir(o, i, this._chuli_ziyuan_jiazai_wancheng.bind(this, c, s));
//             }
//         }
//     };
//     e.prototype.releaseAsset = function (e) {
//         if (e && e.bundle) {
//             var t = Manager.cacheManager.get(e.bundle, e.url, !1);
//             if (!t) {
//                 return;
//             }
//             if (t.shifou_wuxiao) {
//                 return;
//             }
//             if (t.isLoaded) {
//                 if (t.info.retain) {
//                     return;
//                 }
//                 if (Manager.cacheManager.remove_With_Info(e)) {
//                     Manager.releaseManager.release(e);
//                 }
//             } else {
//                 t.status = $resource.AL_Framewrok_Resource.CacheStatus.WAITTING_FOR_RELEASE;
//             }
//         }
//     };
//     e.prototype.retainAsset = function (e) {
//         if (e) {
//             var t = Manager.cacheManager.get(e.bundle, e.url);
//             if (t) {
//                 if (!t.info.retain) {
//                     t.info.retain = e.retain;
//                 }
//                 if (Array.isArray(t.data)) {
//                     for (var o = 0; o < t.data.length; o++) {
//                         if (t.data[o]) {
//                             t.data[o].addRef();
//                         }
//                     }
//                 } else {
//                     if (t.data) {
//                         t.data.addRef();
//                     }
//                 }
//             }
//         }
//     };
//     e.prototype.addPersistAsset = function (e, t, o) {
//         var i = new $resource.AL_Framewrok_Resource.Info();
//         i.url = e;
//         i.data = t;
//         i.bundle = o;
//         i.retain = !0;
//         this.retainAsset(i);
//     };
//     e._instance = null;
//     return e;
// })();
// exports.AssetManager = s;


// 引入相关模块
const $macros = require('./AL_Framework_Macros');
const $resource = require('./AL_Framewrok_Resource');

/** 
 * @class RemoteLoader
 * @description 远程资源加载类，提供加载图片和骨骼动画的方法
 */
class RemoteLoader {
    constructor() {
        this._logTag = '[RemoteLoader] ';
    }

    static Instance() {
        if (!this._instance) {
            this._instance = new RemoteLoader();
        }
        return this._instance;
    }

    /**
     * 加载远程图片资源
     * @param {string} url - 资源的URL
     * @param {boolean} cache - 是否缓存资源
     * @returns {Promise<any>} - 返回一个Promise，解析加载的图片资源
     */
    jiazai_tupian(url, cache = false) {
        return new Promise((resolve) => {
            if (!url || url.length <= 0) {
                resolve(null);
                return;
            }

            const remote_Caches = Manager.cacheManager.remote_Caches;
            if (cache) {
                const spriteFrameCache = remote_Caches.getSpriteFrame(url);
                if (spriteFrameCache && spriteFrameCache.data) {
                    resolve(spriteFrameCache.data);
                    return;
                }

                remote_Caches.remove(url);
            } else {
                remote_Caches.remove(url);
            }

            this._jiazai_yuancheng_ziyuan(url, cc.Texture2D, cache).then((texture) => {
                const cachedData = remote_Caches.get(url);
                if (texture && cachedData) {
                    cachedData.data = texture;
                    cachedData.data.name = url;
                    const updatedCache = remote_Caches.shezhi_sprite_frame(url, cachedData.data);
                    resolve(updatedCache);
                } else {
                    resolve(null);
                }
            });
        });
    }

    /**
     * 加载远程骨骼动画资源
     * @param {string} dir - 资源目录
     * @param {string} name - 资源名称
     * @param {boolean} cache - 是否缓存资源
     * @returns {Promise<any>} - 返回一个Promise，解析加载的骨骼动画资源
     */
    jiazai_spine_donghua_ziyuan(dir, name, cache) {
        return new Promise((resolve) => {
            if (!dir || !name) {
                resolve(null);
                return;
            }

            const fullPath = `${dir}/${name}`;
            const atlasPath = `${fullPath}.atlas`;
            const imagePath = `${fullPath}.png`;
            const jsonPath = `${fullPath}.json`;
            const remoteResource = Manager.releaseManager.huoqu_yuancheng_ziyuan(fullPath);

            if (remoteResource) {
                const cacheData = Manager.cacheManager.remote_Caches.get(fullPath);
                if (cacheData) {
                    cacheData.isLoaded = true;
                    cacheData.data = remoteResource;
                    cacheData.info.data = remoteResource;
                    cacheData.info.url = fullPath;
                    resolve(cacheData.data);
                    cacheData.zhixing_wancheng(cacheData.data);
                } else {
                    const newCacheData = new $resource.AL_Framewrok_Resource.CacheData();
                    newCacheData.info.resourceType = $resource.AL_Framewrok_Resource.Type.Remote;
                    newCacheData.info.type = sp.SkeletonData;
                    newCacheData.info.bundle = $macros.Macro.BUNDLE_REMOTE;
                    newCacheData.isLoaded = true;
                    newCacheData.data = remoteResource;
                    newCacheData.info.data = remoteResource;
                    newCacheData.info.url = fullPath;
                    Manager.cacheManager.remote_Caches.set(fullPath, newCacheData);
                    resolve(newCacheData.data);
                    newCacheData.zhixing_wancheng(newCacheData.data);
                }
                return;
            }

            let cacheData = Manager.cacheManager.remote_Caches.get(fullPath);
            if (cacheData) {
                if (cacheData.isLoaded) {
                    resolve(cacheData.data);
                } else {
                    cacheData.finishCb.push(resolve);
                }
            } else {
                cacheData = new $resource.AL_Framewrok_Resource.CacheData();
                cacheData.info.resourceType = $resource.AL_Framewrok_Resource.Type.Remote;
                cacheData.info.type = sp.SkeletonData;
                cacheData.info.bundle = $macros.Macro.BUNDLE_REMOTE;
                Manager.cacheManager.remote_Caches.set(fullPath, cacheData);

                Promise.all([
                    this._jiazai_yuancheng_ziyuan(imagePath, cc.Texture2D, cache),
                    this._jiazai_yuancheng_ziyuan(jsonPath, cc.JsonAsset, cache),
                    this._jiazai_yuancheng_ziyuan(atlasPath, cc.JsonAsset, cache)
                ]).then(([texture, json, atlas]) => {
                    if (texture && json && atlas) {
                        const skeletonData = new sp.SkeletonData();
                        skeletonData.skeletonJson = json.json;
                        skeletonData.atlasText = atlas.text;
                        skeletonData.textures = [texture];
                        skeletonData.textureNames = [`${name}.png`];
                        cacheData.info.url = fullPath;
                        skeletonData.name = fullPath;
                        cacheData.data = skeletonData;
                        cacheData.isLoaded = true;
                        resolve(cacheData.data);
                        cacheData.zhixing_wancheng(cacheData.data);
                    } else {
                        resolve(null);
                        cacheData.zhixing_wancheng(null);
                        Manager.cacheManager.remote_Caches.remove(fullPath);
                    }
                }).catch(() => {
                    resolve(null);
                    cacheData.zhixing_wancheng(null);
                    Manager.cacheManager.remote_Caches.remove(fullPath);
                });
            }
        });
    }

    /**
     * 加载远程资源
     * @param {string} url - 资源的URL
     * @param {Function} type - 资源类型
     * @returns {Promise<any>} - 返回一个Promise，解析加载的资源
     */
    _jiazai_yuancheng_ziyuan(url, type) {
        return new Promise((resolve) => {
            const cacheData = Manager.cacheManager.remote_Caches.get(url);
            if (cacheData) {
                if (cacheData.isLoaded) {
                    resolve(cacheData.data);
                } else {
                    cacheData.finishCb.push(resolve);
                }
            } else {
                const newCacheData = new $resource.AL_Framewrok_Resource.CacheData();
                newCacheData.info.resourceType = $resource.AL_Framewrok_Resource.Type.Remote;
                newCacheData.info.type = type;
                Manager.cacheManager.remote_Caches.set(url, newCacheData);

                const remoteResource = Manager.releaseManager.huoqu_yuancheng_ziyuan(url);
                if (remoteResource) {
                    newCacheData.isLoaded = true;
                    newCacheData.data = remoteResource;
                    newCacheData.data.addRef();
                    newCacheData.zhixing_wancheng(remoteResource);
                    resolve(newCacheData.data);
                } else {
                    cc.assetManager.loadRemote(url, (err, asset) => {
                        newCacheData.isLoaded = true;
                        if (asset) {
                            newCacheData.data = asset;
                            newCacheData.data.addRef();
                        }
                        newCacheData.zhixing_wancheng(asset);
                        resolve(newCacheData.data);
                    });
                }
            }
        });
    }

    update() {}
}

// 初始化静态变量
RemoteLoader._instance = null;

/** 
 * @class AssetManager
 * @description 资源管理类，提供加载和释放资源的方法
 */
class AssetManager {
    constructor() {
        this.logTag = '[AssetManager]: ';
        this._remote = new RemoteLoader();
    }

    static Instance() {
        if (!this._instance) {
            this._instance = new AssetManager();
        }
        return this._instance;
    }

    get remote() {
        return this._remote;
    }

    /**
     * 获取资源包
     * @param {string} bundleName - 资源包名称
     * @returns {any} - 资源包
     */
    getBundle(bundleName) {
        return Manager.bundleManager.getBundle(bundleName);
    }

    /**
     * 加载资源
     * @param {Object} options - 加载选项
     */
    load(options) {
        const { bundle, path, type, onProgress, onComplete, shifou_yanchi_shifang_ziyuan } = options;

        let cacheData = Manager.cacheManager.get(bundle, path);
        if (cacheData) {
            if (cacheData.isLoaded) {
                onComplete(cacheData);
            } else {
                cacheData.finishCb.push(onComplete);
                cacheData.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
            }
        } else {
            cacheData = new $resource.AL_Framewrok_Resource.CacheData();
            cacheData.info.url = path;
            cacheData.info.type = type;
            cacheData.info.bundle = bundle;
            cacheData.info.shifou_yanchi_shifang_ziyuan = shifou_yanchi_shifang_ziyuan;
            Manager.cacheManager.set(bundle, path, cacheData);
            console.time(`加载资源 : ${cacheData.info.url}`);

            const localResource = Manager.releaseManager.get(bundle, path);
            if (localResource) {
                this._chuli_ziyuan_jiazai_wancheng(cacheData, onComplete, null, localResource);
                return;
            }

            const bundleInstance = this.getBundle(bundle);
            if (!bundleInstance) {
                const error = new Error(`${this.logTag} ${bundle} 没有加载，请先加载`);
                this._chuli_ziyuan_jiazai_wancheng(cacheData, onComplete, error, null);
                return;
            }

            if (onProgress) {
                bundleInstance.load(path, type, onProgress, this._chuli_ziyuan_jiazai_wancheng.bind(this, cacheData, onComplete));
            } else {
                bundleInstance.load(path, type, this._chuli_ziyuan_jiazai_wancheng.bind(this, cacheData, onComplete));
            }
        }
    }

    /**
     * 资源加载完成的回调函数
     * @param {Object} cacheData - 缓存数据
     * @param {Function} onComplete - 完成回调函数
     * @param {Error} [error] - 错误信息
     * @param {any} [resource] - 加载的资源
     */
    _chuli_ziyuan_jiazai_wancheng(cacheData, onComplete, error, resource) {
        cacheData.isLoaded = true;
        if (error) {
            Log.e(`${this.logTag}加载资源失败:${cacheData.info.url} 原因:${error.message || '未知'}`);
            cacheData.data = null;
            Manager.cacheManager.remove(cacheData.info.bundle, cacheData.info.url);
            onComplete(cacheData);
        } else {
            cacheData.data = resource;
            onComplete(cacheData);
        }
        cacheData.zhixing_wancheng(cacheData);

        if (cacheData.status === $resource.AL_Framewrok_Resource.CacheStatus.WAITTING_FOR_RELEASE && cacheData.data) {
            cacheData.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
            const info = new $resource.AL_Framewrok_Resource.Info();
            info.url = cacheData.info.url;
            info.type = cacheData.info.type;
            info.data = cacheData.data;
            info.bundle = cacheData.info.bundle;
            info.shifou_yanchi_shifang_ziyuan = cacheData.info.shifou_yanchi_shifang_ziyuan;
            this.releaseAsset(info);
        }

        console.timeEnd(`加载资源 : ${cacheData.info.url}`);
    }

    /**
     * 加载目录资源
     * @param {Object} options - 加载选项
     */
    loadDir(options) {
        const { bundle, path, type, onProgress, onComplete, shifou_yanchi_shifang_ziyuan } = options;

        let cacheData = Manager.cacheManager.get(bundle, path);
        if (cacheData) {
            if (cacheData.isLoaded) {
                onComplete(cacheData);
            } else {
                cacheData.finishCb.push(onComplete);
                cacheData.status = $resource.AL_Framewrok_Resource.CacheStatus.NONE;
            }
        } else {
            cacheData = new $resource.AL_Framewrok_Resource.CacheData();
            cacheData.info.url = path;
            cacheData.info.type = type;
            cacheData.info.bundle = bundle;
            cacheData.info.shifou_yanchi_shifang_ziyuan = shifou_yanchi_shifang_ziyuan;
            Manager.cacheManager.set(bundle, path, cacheData);
            console.time(`加载资源 : ${cacheData.info.url}`);

            const localResource = Manager.releaseManager.get(bundle, path);
            if (localResource) {
                this._chuli_ziyuan_jiazai_wancheng(cacheData, onComplete, null, localResource);
                return;
            }

            const bundleInstance = this.getBundle(bundle);
            if (!bundleInstance) {
                const error = new Error(`${this.logTag} ${bundle} 没有加载，请先加载`);
                this._chuli_ziyuan_jiazai_wancheng(cacheData, onComplete, error, null);
                return;
            }

            if (onProgress) {
                bundleInstance.loadDir(path, type, onProgress, this._chuli_ziyuan_jiazai_wancheng.bind(this, cacheData, onComplete));
            } else {
                bundleInstance.loadDir(path, type, this._chuli_ziyuan_jiazai_wancheng.bind(this, cacheData, onComplete));
            }
        }
    }

    /**
     * 释放资源
     * @param {Object} info - 资源信息
     */
    releaseAsset(info) {
        if (info && info.bundle) {
            const cacheData = Manager.cacheManager.get(info.bundle, info.url, false);
            if (!cacheData) return;
            if (cacheData.shifou_wuxiao) return;
            if (cacheData.isLoaded) {
                if (cacheData.info.retain) return;
                if (Manager.cacheManager.remove_With_Info(info)) {
                    Manager.releaseManager.release(info);
                }
            } else {
                cacheData.status = $resource.AL_Framewrok_Resource.CacheStatus.WAITTING_FOR_RELEASE;
            }
        }
    }

    /**
     * 保持资源
     * @param {Object} info - 资源信息
     */
    retainAsset(info) {
        if (info) {
            const cacheData = Manager.cacheManager.get(info.bundle, info.url);
            if (cacheData) {
                if (!cacheData.info.retain) {
                    cacheData.info.retain = info.retain;
                }
                if (Array.isArray(cacheData.data)) {
                    for (const data of cacheData.data) {
                        if (data) {
                            data.addRef();
                        }
                    }
                } else if (cacheData.data) {
                    cacheData.data.addRef();
                }
            }
        }
    }

    /**
     * 添加持久化资源
     * @param {string} url - 资源URL
     * @param {any} data - 资源数据
     * @param {string} bundle - 资源包
     */
    addPersistAsset(url, data, bundle) {
        const info = new $resource.AL_Framewrok_Resource.Info();
        info.url = url;
        info.data = data;
        info.bundle = bundle;
        info.retain = true;
        this.retainAsset(info);
    }
}

// 初始化静态变量
AssetManager._instance = null;

// 导出AssetManager类
exports.AssetManager = AssetManager;
